<template>
	<view class="ys">
		<view class="box">
			<view class="top">
				<image src="/static/img/pg.png" mode="widthFix"></image>
				<view class="topbox">
					<view class="text">
						当前余额
					</view>
					<view class="num">
						{{balance || 0}}
					</view>
				</view>
			</view>
			<view class="bot" v-if="false">
				<view class="botitem">
					累计获得 <text>0</text>
				</view>
				<view class="botitem">
					累计使用 <text>0</text>
				</view>
			</view>
		</view>
		<view class="title">
			<text>使用记录</text>
			<!-- <view class="more">积分记录 <u-icon name="arrow-right"></u-icon> </view> -->
		</view>
		<view class="list">
			<view class="item" v-for="(item,index) in list" :key="index">
				<view class="left">
					<view class="name">
						{{item.remarks}}
					</view>
					<view class="time">
						{{item.add_time | ysTime}}
					</view>
				</view>
				<view class="right">
					<view class="num">
						<text v-if="item.regulation == 1">+</text>
						<text v-else>-</text>
						{{Number(item.num)}}
					</view>
					<text class="balance">余额：{{item.balance}}</text>
				</view>
			</view>
			<view class="no-list" v-if="list.length == 0">
				- 暂无数据 -
			</view>
		</view>

	</view>
</template>

<script>
	import {
		balanceDetails,
	} from "@/api/user.js"
	import {
		UserInfo
	} from "@/api/api.js"
	export default {
		data() {
			return {
				coin: "积分",
				list: [],
				page: 1,
				last_page: 1,
				balance: 0,
				type: 1
			}
		},

		onLoad(e) {
			if (e.type) {
				this.type = e.type
			}
			this.MyQuan()
			this.UserInfo()
		},
		onReachBottom() {
			if (this.page < this.last_page) {
				this.page++
				this.MyQuan()
			}
		},
		methods: {
			UserInfo() {
				UserInfo().then(res => {
					if (res.status == 1) {
						this.balance = res.data.user.balance_1
					} else {
						uni.$showMsg(res.message)
					}
				})
			},
			MyQuan() {
				balanceDetails().then(res => {
					if (res.status == 1) {
						this.list = this.list.concat(res.data.FinanceList)
						this.last_page = res.data.last_page
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.ys {
		padding-top: 10px;
		background: #f2f2f2;
		min-height: 100vh;
		height: 100%;
		/* #ifdef H5 */
		min-height: calc(100vh - 44px);
		/* #endif */
		box-sizing: border-box;
	}

	.list {
		background: #fff;
		border-radius: 8px;
		padding: 10px;
		width: 94%;
		margin: 0 auto;
		box-sizing: border-box;

		.item {
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 10px 0;
			font-size: 14px;

			.left {
				.name {
					margin-bottom: 5px;

					text {
						color: #777;
						font-size: 12px;
						margin-left: 5px;
					}
				}

				.time {
					font-size: 12px;
					color: #777;
				}
			}

			.right {
				font-weight: bold;
				display: flex;
				flex-direction: column;
				align-items: flex-end;

				.num {
					display: flex;
					align-items: center;
					margin-bottom: 5px;
				}

				.balance {
					font-weight: normal;
					font-size: 12px;
					color: #777;
				}
			}
		}
	}

	.title {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 15px 3%;
		box-sizing: border-box;
		margin-top: 10px;

		text {
			font-weight: bold;
			font-size: 15px;
		}

		.more {
			display: flex;
			align-items: center;
			font-size: 12px;
			color: #777;

		}
	}

	.box {
		background: #fff;
		width: 94%;
		margin: 0 auto;
		box-sizing: border-box;
		border-radius: 10px;
		// border: 1px solid #0066FF;

		.top {
			color: #fff;
			font-size: 14px;
			width: 100%;
			position: relative;

			image {
				width: 100%;
				border-radius: 10px;
			}

			.topbox {
				position: absolute;
				top: 0;
				left: 0;
				width: 100%;
				height: 100%;
				padding: 30px 20px;
				box-sizing: border-box;
			}

			.num {
				margin-top: 5px;
				font-weight: bold;
				font-size: 25px;
			}
		}

		.bot {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.botitem {
				flex: 1;
				text-align: center;
				font-size: 14px;
				padding: 15px 0;
				color: #777;

				text {
					font-weight: bold;
					margin-left: 10px;
					color: #0066FF;
				}
			}
		}
	}
</style>